<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">

      <el-form-item label="" prop="orderSn">
        <el-input
          v-model="queryParams.orderSn"
          placeholder="请输入订单号"
          clearable
          style="width: 240px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item label="" prop="userName">
        <el-input
          v-model="queryParams.userName"
          placeholder="借款人"
          clearable
          style="width: 240px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item label="" prop="userPhone">
        <el-input
          v-model="queryParams.userPhone"
          placeholder="请输入手机号码"
          clearable
          style="width: 240px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item label="">
        <el-date-picker
          v-model="dateRange"
          style="width: 240px"
          value-format="yyyy-MM-dd"
          type="daterange"
          range-separator="-"
          start-placeholder="申请开始日期"
          end-placeholder="申请结束日期"
        ></el-date-picker>
      </el-form-item>

      <el-form-item label="">
        <el-date-picker
          v-model="dateRange1"
          style="width: 240px"
          value-format="yyyy-MM-dd"
          type="daterange"
          range-separator="-"
          start-placeholder="放款开始日期"
          end-placeholder="放款结束日期"
        ></el-date-picker>
      </el-form-item>

      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-table v-loading="loading" :data="applyList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="50" align="center"/>
      <el-table-column label="平台" align="center" prop="companyId"/>
      <el-table-column label="订单号" align="center" prop="orderSn"/>
      <el-table-column label="贷款用户" align="center" prop="userName"/>
      <el-table-column label="手机号码" align="center" prop="userPhone"/>
      <el-table-column label="借款金额" align="center" prop="realApplyMoney"/>
      <el-table-column label="周期" align="center" prop="applyCycle"/>

      <el-table-column label="申请时间" align="center" prop="createTime" width="160">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="放款时间" align="center" prop="applyTime" width="160">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.applyTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="放款流水号" align="center" prop="payLogEntity.bankOrderNo"/>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

  </div>
</template>

<script>
import {listPaySuccess} from "@/api/app/apply";

export default {
  name: "PaySuccess",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 订单表格数据
      applyList: null,
      // 公司数据
      companyList: null,
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 日期范围
      dateRange: [],
      dateRange1: [],
      // 表单参数
      form: {},
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        userPhone: undefined,
        userName: undefined,
        orderSn: undefined
      }
    };
  },
  watch: {},
  created() {
    this.getList();
  },
  methods: {
    /** 查询列表 */
    getList() {
      this.loading = true;
      if (this.dateRange1 && Array.isArray(this.dateRange1)) {
        this.queryParams.applyStartTime = this.dateRange1[0];
        this.queryParams.applyEndTime = this.dateRange1[1];
      }
      listPaySuccess(this.addDateRange(this.queryParams, this.dateRange)).then(response => {
          this.applyList = response.rows;
          this.total = response.total;
          this.loading = false;
        }
      );
    },

    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: undefined,
        realApplyMoney: 0,
        manageMoney: 0,
        riskMoney: 0,
        applyServiceCharge: 0,
        applyCycle: 0,
        realPayMoney: 0,
        interestMoney: 0,
        overDay: 0,
        overMoney: 0,
        paymentMoney: 0
      };
      this.resetForm("form");
    },

    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange = [];
      this.dateRange1 = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },

    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },

    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id);
      this.single = selection.length != 1;
      this.multiple = !selection.length;
    },

    handlePayment(row) {
      this.reset();
      this.form = row;
      this.form.realPayMoney = this.form.realApplyMoney - this.form.manageMoney - this.form.riskMoney - this.form.applyServiceCharge;
      this.open = true;
    },

    submitHandlerPayment(type) {
      this.$refs["form"].validate(valid => {
        if (valid) {
          let that = this.form;
          this.$modal.confirm('是否确认对编号为"' + this.form.orderSn + '"的订单还款？').then(function () {
            return handlePayment(that.id, '0', that.paymentMoney, type, type);
          }).then(() => {
            this.getList();
            this.open = false;
            this.$modal.msgSuccess("还款成功");
          }).catch((e) => {
          });
        }
      })
    },


    /** 提交按钮 */
    submitForm: function () {

    },
    /** 删除按钮操作 */
    handleDelete(row) {

    },


  }
};
</script>
